package org.serverct.finalfight.game.hadesgame.events;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.serverct.finalfight.game.hadesgame.EventType;
import org.serverct.finalfight.internal.game.basic.BasicGame;
import org.serverct.finalfight.internal.game.hadesgame.ContinuousEvent;
import org.serverct.finalfight.internal.game.hadesgame.Factorable;

public class BadMood extends ContinuousEvent implements Listener, Factorable {

    public BadMood(BasicGame game, EventType type) {
        super(game, type);
        this.setFactor((int) (Math.random() * 5));
    }

    @Override
    public void start() {
        this.factor = (int) (Math.random() * 3 + 2);
    }

    @EventHandler
    public void onDamaged(EntityDamageByEntityEvent event) {
        if (!(event.getEntity() instanceof Player)) {
            return;
        }
        Player player = (Player) event.getEntity();
        if (this.game.players.containsKey(player.getUniqueId())) {
            if (this.game.isAlive(player)) {
                event.setDamage(event.getDamage() * this.factor);
            }
        }
    }

    @Override
    public void setFactor(double factor) {
        this.factor = factor;
    }

    @Override
    public double getFactor() {
        return this.factor;
    }
}
